Imports System.Xml
Imports System.IO

Public Class Main
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
    Friend WithEvents FolderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnBrowseFolder As System.Windows.Forms.Button
    Friend WithEvents txtProfilerDir As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents btnXML As System.Windows.Forms.Button
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents txtXML As System.Windows.Forms.TextBox
    Friend WithEvents btnCreate As System.Windows.Forms.Button
    Friend WithEvents btnXBMCDir As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents txtXBMCDir As System.Windows.Forms.TextBox
    Friend WithEvents chkCreateEmptyMovie As System.Windows.Forms.CheckBox
    Friend WithEvents chkOverwriteMovie As System.Windows.Forms.CheckBox
    Friend WithEvents chkCreateCover As System.Windows.Forms.CheckBox
    Friend WithEvents chkOverwriteCover As System.Windows.Forms.CheckBox
    Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents RadioButton5 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton6 As System.Windows.Forms.RadioButton
    Friend WithEvents chkDVDFolder As System.Windows.Forms.CheckBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
    Friend WithEvents chkDuplicates As System.Windows.Forms.CheckBox
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents lblLog As System.Windows.Forms.Label
    Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents rdoVer2 As System.Windows.Forms.RadioButton
    Friend WithEvents rdoVer3 As System.Windows.Forms.RadioButton
    Friend WithEvents Label11 As System.Windows.Forms.Label
    Friend WithEvents Label12 As System.Windows.Forms.Label
    Friend WithEvents btnPreview As System.Windows.Forms.Button
    Friend WithEvents Label13 As System.Windows.Forms.Label
    Friend WithEvents Label14 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Main))
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        Me.MenuItem3 = New System.Windows.Forms.MenuItem
        Me.MenuItem4 = New System.Windows.Forms.MenuItem
        Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog
        Me.Label1 = New System.Windows.Forms.Label
        Me.txtProfilerDir = New System.Windows.Forms.TextBox
        Me.btnBrowseFolder = New System.Windows.Forms.Button
        Me.Label2 = New System.Windows.Forms.Label
        Me.btnXML = New System.Windows.Forms.Button
        Me.txtXML = New System.Windows.Forms.TextBox
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.btnCreate = New System.Windows.Forms.Button
        Me.btnXBMCDir = New System.Windows.Forms.Button
        Me.txtXBMCDir = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.chkCreateEmptyMovie = New System.Windows.Forms.CheckBox
        Me.chkOverwriteMovie = New System.Windows.Forms.CheckBox
        Me.chkCreateCover = New System.Windows.Forms.CheckBox
        Me.chkOverwriteCover = New System.Windows.Forms.CheckBox
        Me.RadioButton1 = New System.Windows.Forms.RadioButton
        Me.RadioButton2 = New System.Windows.Forms.RadioButton
        Me.RadioButton3 = New System.Windows.Forms.RadioButton
        Me.RadioButton4 = New System.Windows.Forms.RadioButton
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.RadioButton6 = New System.Windows.Forms.RadioButton
        Me.RadioButton5 = New System.Windows.Forms.RadioButton
        Me.chkDVDFolder = New System.Windows.Forms.CheckBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.Label7 = New System.Windows.Forms.Label
        Me.Label8 = New System.Windows.Forms.Label
        Me.Label9 = New System.Windows.Forms.Label
        Me.Label10 = New System.Windows.Forms.Label
        Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
        Me.chkDuplicates = New System.Windows.Forms.CheckBox
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.lblLog = New System.Windows.Forms.Label
        Me.StatusBar1 = New System.Windows.Forms.StatusBar
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.rdoVer3 = New System.Windows.Forms.RadioButton
        Me.rdoVer2 = New System.Windows.Forms.RadioButton
        Me.Label11 = New System.Windows.Forms.Label
        Me.Label12 = New System.Windows.Forms.Label
        Me.btnPreview = New System.Windows.Forms.Button
        Me.Label13 = New System.Windows.Forms.Label
        Me.Label14 = New System.Windows.Forms.Label
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.SuspendLayout()
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem3})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2})
        Me.MenuItem1.Text = "File"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 0
        Me.MenuItem2.Text = "Exit"
        '
        'MenuItem3
        '
        Me.MenuItem3.Index = 1
        Me.MenuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem4})
        Me.MenuItem3.Text = "Help"
        '
        'MenuItem4
        '
        Me.MenuItem4.Index = 0
        Me.MenuItem4.Text = "About"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(32, 288)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(128, 23)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "DVD Profiler Directory:"
        '
        'txtProfilerDir
        '
        Me.txtProfilerDir.Location = New System.Drawing.Point(32, 304)
        Me.txtProfilerDir.Name = "txtProfilerDir"
        Me.txtProfilerDir.Size = New System.Drawing.Size(488, 20)
        Me.txtProfilerDir.TabIndex = 1
        Me.txtProfilerDir.Text = ""
        '
        'btnBrowseFolder
        '
        Me.btnBrowseFolder.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btnBrowseFolder.Location = New System.Drawing.Point(528, 304)
        Me.btnBrowseFolder.Name = "btnBrowseFolder"
        Me.btnBrowseFolder.TabIndex = 2
        Me.btnBrowseFolder.Text = "Browse"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(32, 352)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(128, 23)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "DVD Profiler XML:"
        '
        'btnXML
        '
        Me.btnXML.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btnXML.Location = New System.Drawing.Point(528, 368)
        Me.btnXML.Name = "btnXML"
        Me.btnXML.TabIndex = 5
        Me.btnXML.Text = "Browse"
        '
        'txtXML
        '
        Me.txtXML.Location = New System.Drawing.Point(32, 368)
        Me.txtXML.Name = "txtXML"
        Me.txtXML.Size = New System.Drawing.Size(488, 20)
        Me.txtXML.TabIndex = 4
        Me.txtXML.Text = ""
        '
        'btnCreate
        '
        Me.btnCreate.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btnCreate.Location = New System.Drawing.Point(528, 504)
        Me.btnCreate.Name = "btnCreate"
        Me.btnCreate.Size = New System.Drawing.Size(75, 64)
        Me.btnCreate.TabIndex = 6
        Me.btnCreate.Text = "Start"
        '
        'btnXBMCDir
        '
        Me.btnXBMCDir.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btnXBMCDir.Location = New System.Drawing.Point(528, 432)
        Me.btnXBMCDir.Name = "btnXBMCDir"
        Me.btnXBMCDir.TabIndex = 9
        Me.btnXBMCDir.Text = "Browse"
        '
        'txtXBMCDir
        '
        Me.txtXBMCDir.Location = New System.Drawing.Point(32, 432)
        Me.txtXBMCDir.Name = "txtXBMCDir"
        Me.txtXBMCDir.Size = New System.Drawing.Size(488, 20)
        Me.txtXBMCDir.TabIndex = 8
        Me.txtXBMCDir.Text = ""
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(32, 416)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(128, 23)
        Me.Label3.TabIndex = 7
        Me.Label3.Text = "XBMC DVD Directory:"
        '
        'chkCreateEmptyMovie
        '
        Me.chkCreateEmptyMovie.Location = New System.Drawing.Point(32, 496)
        Me.chkCreateEmptyMovie.Name = "chkCreateEmptyMovie"
        Me.chkCreateEmptyMovie.Size = New System.Drawing.Size(128, 24)
        Me.chkCreateEmptyMovie.TabIndex = 10
        Me.chkCreateEmptyMovie.Text = "Create Empty Movie"
        '
        'chkOverwriteMovie
        '
        Me.chkOverwriteMovie.Enabled = False
        Me.chkOverwriteMovie.Location = New System.Drawing.Point(160, 608)
        Me.chkOverwriteMovie.Name = "chkOverwriteMovie"
        Me.chkOverwriteMovie.Size = New System.Drawing.Size(120, 32)
        Me.chkOverwriteMovie.TabIndex = 11
        Me.chkOverwriteMovie.Text = "Overwrite Existing Movie File"
        Me.chkOverwriteMovie.Visible = False
        '
        'chkCreateCover
        '
        Me.chkCreateCover.Location = New System.Drawing.Point(320, 496)
        Me.chkCreateCover.Name = "chkCreateCover"
        Me.chkCreateCover.Size = New System.Drawing.Size(192, 24)
        Me.chkCreateCover.TabIndex = 12
        Me.chkCreateCover.Text = "Create DVD Cover Thumbnail"
        '
        'chkOverwriteCover
        '
        Me.chkOverwriteCover.Enabled = False
        Me.chkOverwriteCover.Location = New System.Drawing.Point(320, 520)
        Me.chkOverwriteCover.Name = "chkOverwriteCover"
        Me.chkOverwriteCover.Size = New System.Drawing.Size(184, 24)
        Me.chkOverwriteCover.TabIndex = 13
        Me.chkOverwriteCover.Text = "Overwrite Existing DVD Covers"
        '
        'RadioButton1
        '
        Me.RadioButton1.Location = New System.Drawing.Point(16, 24)
        Me.RadioButton1.Name = "RadioButton1"
        Me.RadioButton1.Size = New System.Drawing.Size(56, 24)
        Me.RadioButton1.TabIndex = 14
        Me.RadioButton1.Text = "iso"
        '
        'RadioButton2
        '
        Me.RadioButton2.Location = New System.Drawing.Point(16, 48)
        Me.RadioButton2.Name = "RadioButton2"
        Me.RadioButton2.Size = New System.Drawing.Size(56, 24)
        Me.RadioButton2.TabIndex = 15
        Me.RadioButton2.Text = "img"
        '
        'RadioButton3
        '
        Me.RadioButton3.Location = New System.Drawing.Point(88, 24)
        Me.RadioButton3.Name = "RadioButton3"
        Me.RadioButton3.Size = New System.Drawing.Size(48, 24)
        Me.RadioButton3.TabIndex = 16
        Me.RadioButton3.Text = "vob"
        '
        'RadioButton4
        '
        Me.RadioButton4.Location = New System.Drawing.Point(88, 48)
        Me.RadioButton4.Name = "RadioButton4"
        Me.RadioButton4.Size = New System.Drawing.Size(48, 24)
        Me.RadioButton4.TabIndex = 17
        Me.RadioButton4.Text = "mpg"
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.RadioButton6)
        Me.GroupBox1.Controls.Add(Me.RadioButton5)
        Me.GroupBox1.Controls.Add(Me.RadioButton1)
        Me.GroupBox1.Controls.Add(Me.RadioButton2)
        Me.GroupBox1.Controls.Add(Me.RadioButton3)
        Me.GroupBox1.Controls.Add(Me.RadioButton4)
        Me.GroupBox1.Enabled = False
        Me.GroupBox1.Location = New System.Drawing.Point(32, 528)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(232, 80)
        Me.GroupBox1.TabIndex = 18
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "File Extension"
        '
        'RadioButton6
        '
        Me.RadioButton6.Location = New System.Drawing.Point(160, 48)
        Me.RadioButton6.Name = "RadioButton6"
        Me.RadioButton6.Size = New System.Drawing.Size(48, 24)
        Me.RadioButton6.TabIndex = 19
        Me.RadioButton6.Text = "wmv"
        '
        'RadioButton5
        '
        Me.RadioButton5.Location = New System.Drawing.Point(160, 24)
        Me.RadioButton5.Name = "RadioButton5"
        Me.RadioButton5.Size = New System.Drawing.Size(48, 24)
        Me.RadioButton5.TabIndex = 18
        Me.RadioButton5.Text = "avi"
        '
        'chkDVDFolder
        '
        Me.chkDVDFolder.Enabled = False
        Me.chkDVDFolder.Location = New System.Drawing.Point(160, 496)
        Me.chkDVDFolder.Name = "chkDVDFolder"
        Me.chkDVDFolder.Size = New System.Drawing.Size(128, 24)
        Me.chkDVDFolder.TabIndex = 19
        Me.chkDVDFolder.Text = "Create DVD Folder"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(16, 272)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(440, 16)
        Me.Label4.TabIndex = 20
        Me.Label4.Text = "1. Locate the DVD Profiler user data directory (used for grabbing DVD cover image" & _
        "s)"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(16, 336)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(224, 16)
        Me.Label5.TabIndex = 21
        Me.Label5.Text = "2. Locate the exported collection in XML"
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(16, 144)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(400, 16)
        Me.Label6.TabIndex = 22
        Me.Label6.Text = "Before you begin, you must export your DVD Profiler collection into XML format"
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(16, 400)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(344, 16)
        Me.Label7.TabIndex = 23
        Me.Label7.Text = "3.  Select location to export DVD information (thumbnails and files)"
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(16, 472)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(248, 16)
        Me.Label8.TabIndex = 24
        Me.Label8.Text = "4. Select DVD output format"
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(304, 472)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(208, 16)
        Me.Label9.TabIndex = 25
        Me.Label9.Text = "5. Create DVD Cover thumbnail"
        '
        'Label10
        '
        Me.Label10.Location = New System.Drawing.Point(16, 664)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(608, 40)
        Me.Label10.TabIndex = 26
        Me.Label10.Text = "Output filenames are based on the movie title stored by DVD Profiler.  If ""Allowe" & _
        "d Duplicates"" is checked, DVDs with the same title will have (Duplicate #) added" & _
        " to the filename with up to 4 duplicates per title allowed."
        '
        'ProgressBar1
        '
        Me.ProgressBar1.Location = New System.Drawing.Point(320, 576)
        Me.ProgressBar1.Name = "ProgressBar1"
        Me.ProgressBar1.Size = New System.Drawing.Size(296, 23)
        Me.ProgressBar1.TabIndex = 27
        '
        'chkDuplicates
        '
        Me.chkDuplicates.Enabled = False
        Me.chkDuplicates.Location = New System.Drawing.Point(32, 608)
        Me.chkDuplicates.Name = "chkDuplicates"
        Me.chkDuplicates.Size = New System.Drawing.Size(120, 32)
        Me.chkDuplicates.TabIndex = 28
        Me.chkDuplicates.Text = "Allow Duplicates"
        '
        'PictureBox1
        '
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
        Me.PictureBox1.Location = New System.Drawing.Point(144, 16)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(312, 96)
        Me.PictureBox1.TabIndex = 29
        Me.PictureBox1.TabStop = False
        '
        'lblLog
        '
        Me.lblLog.Location = New System.Drawing.Point(320, 608)
        Me.lblLog.Name = "lblLog"
        Me.lblLog.Size = New System.Drawing.Size(296, 40)
        Me.lblLog.TabIndex = 30
        '
        'StatusBar1
        '
        Me.StatusBar1.Location = New System.Drawing.Point(0, 717)
        Me.StatusBar1.Name = "StatusBar1"
        Me.StatusBar1.Size = New System.Drawing.Size(648, 22)
        Me.StatusBar1.SizingGrip = False
        Me.StatusBar1.TabIndex = 31
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.rdoVer3)
        Me.GroupBox2.Controls.Add(Me.rdoVer2)
        Me.GroupBox2.Location = New System.Drawing.Point(32, 168)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(136, 96)
        Me.GroupBox2.TabIndex = 32
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "Collection Version"
        '
        'rdoVer3
        '
        Me.rdoVer3.Location = New System.Drawing.Point(16, 56)
        Me.rdoVer3.Name = "rdoVer3"
        Me.rdoVer3.Size = New System.Drawing.Size(112, 24)
        Me.rdoVer3.TabIndex = 1
        Me.rdoVer3.Text = "DVD Profiler 3.x"
        '
        'rdoVer2
        '
        Me.rdoVer2.Location = New System.Drawing.Point(16, 16)
        Me.rdoVer2.Name = "rdoVer2"
        Me.rdoVer2.Size = New System.Drawing.Size(112, 24)
        Me.rdoVer2.TabIndex = 0
        Me.rdoVer2.Text = "DVD Profiler 2.x"
        '
        'Label11
        '
        Me.Label11.Location = New System.Drawing.Point(184, 176)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(384, 23)
        Me.Label11.TabIndex = 33
        Me.Label11.Text = "Version 2 image data is stored in the Program Files location of DVD Profiler"
        '
        'Label12
        '
        Me.Label12.Location = New System.Drawing.Point(184, 224)
        Me.Label12.Name = "Label12"
        Me.Label12.Size = New System.Drawing.Size(392, 23)
        Me.Label12.TabIndex = 34
        Me.Label12.Text = "Version 3 image data is stored in the My Documents location of DVD Profiler"
        '
        'btnPreview
        '
        Me.btnPreview.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.btnPreview.Location = New System.Drawing.Point(528, 472)
        Me.btnPreview.Name = "btnPreview"
        Me.btnPreview.TabIndex = 35
        Me.btnPreview.Text = "Preview"
        '
        'Label13
        '
        Me.Label13.Location = New System.Drawing.Point(184, 192)
        Me.Label13.Name = "Label13"
        Me.Label13.Size = New System.Drawing.Size(384, 23)
        Me.Label13.TabIndex = 36
        Me.Label13.Text = "Example: C:\Program Files\InterVocative Software\DVD Profiler"
        '
        'Label14
        '
        Me.Label14.Location = New System.Drawing.Point(184, 240)
        Me.Label14.Name = "Label14"
        Me.Label14.Size = New System.Drawing.Size(440, 23)
        Me.Label14.TabIndex = 37
        Me.Label14.Text = "Example: C:\Documents and Settings\username\My Documents\DVD Profiler"
        '
        'Main
        '
        Me.AutoScale = False
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(648, 739)
        Me.Controls.Add(Me.Label14)
        Me.Controls.Add(Me.Label13)
        Me.Controls.Add(Me.btnPreview)
        Me.Controls.Add(Me.Label12)
        Me.Controls.Add(Me.Label11)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.StatusBar1)
        Me.Controls.Add(Me.lblLog)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.chkDuplicates)
        Me.Controls.Add(Me.ProgressBar1)
        Me.Controls.Add(Me.Label10)
        Me.Controls.Add(Me.Label9)
        Me.Controls.Add(Me.Label8)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.chkDVDFolder)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.chkOverwriteCover)
        Me.Controls.Add(Me.chkCreateCover)
        Me.Controls.Add(Me.chkOverwriteMovie)
        Me.Controls.Add(Me.chkCreateEmptyMovie)
        Me.Controls.Add(Me.btnXBMCDir)
        Me.Controls.Add(Me.txtXBMCDir)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.btnCreate)
        Me.Controls.Add(Me.btnXML)
        Me.Controls.Add(Me.txtXML)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.btnBrowseFolder)
        Me.Controls.Add(Me.txtProfilerDir)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.Menu = Me.MainMenu1
        Me.Name = "Main"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "DVDProfiler2XBMC 2.1"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btnBrowseFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowseFolder.Click

        Dim fbd As New FolderBrowserDialog

        fbd.ShowDialog()

        Me.txtProfilerDir.Text = fbd.SelectedPath.ToString

    End Sub

    Private Sub btnXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXML.Click

        Dim filebd As New OpenFileDialog

        filebd.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*"

        filebd.ShowDialog()

        Me.txtXML.Text = filebd.FileName.ToString

    End Sub

    Private Sub btnXBMCDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXBMCDir.Click

        Dim fbd As New FolderBrowserDialog

        fbd.RootFolder = Environment.SpecialFolder.MyComputer

        fbd.ShowDialog()

        Me.txtXBMCDir.Text = fbd.SelectedPath.ToString

    End Sub

    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.chkCreateCover.Checked = True
        Me.chkCreateEmptyMovie.Checked = True
        LoadConfiguration()

    End Sub

    Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click

        Try
            Dim m_xmld As XmlDocument
            Dim m_nodelist As XmlNodeList
            Dim m_node As XmlNode
            Dim count As Integer = 0
            Dim intTotal As Integer
            Dim indSortTitle As Integer
            Dim indTitleID As Integer
            Dim strVersion As String
            Dim nodecount As Integer = 0

            If Not (Me.rdoVer2.Checked Or Me.rdoVer3.Checked) Then
                MsgBox("Please select your version of DVD Profiler")
                Exit Sub
            End If

            If Me.txtXML.Text = "" Then
                MsgBox("Please select an XML file.")
                Me.txtXML.Focus()
                Exit Sub
            End If

            If Me.txtXBMCDir.Text = "" Then
                MsgBox("Please select an output directory.")
                Me.txtXBMCDir.Focus()
                Exit Sub
            End If

            If Not File.Exists(Me.txtXML.Text) Then
                MsgBox("File does not exist.  Please select a valid file.")
                Me.txtXML.Focus()
                Exit Sub
            End If

            If Not Directory.Exists(Me.txtXBMCDir.Text) Then
                MsgBox("Output location is invalid or does not exist.  Please choose a valid location.")
                Me.txtXBMCDir.Focus()
                Exit Sub
            End If

            If Me.chkOverwriteMovie.Checked Then
                MsgBox("You have selected to overwrite movie files.  Are you sure you want to overwrite ALL files?")
            End If

            'Create the XML Document
            m_xmld = New XmlDocument

            'Load the Xml file
            m_xmld.Load(Me.txtXML.Text)

            'Get the list of name nodes 
            m_nodelist = m_xmld.SelectNodes("/Collection/DVD")

            Me.lblLog.Text = ""
            Me.Update()

            Me.ProgressBar1.Maximum = m_nodelist.Count
            Me.ProgressBar1.Minimum = 0
            Me.ProgressBar1.BackColor = Color.Blue
            Me.ProgressBar1.Value = 0

            'For nodecount = 0 To m_nodelist.Item(0).ChildNodes.Count - 1
            '    If m_nodelist.Item(0).ChildNodes.Item(count).Name = "ID" Then
            '        indTitleID = count
            '    End If
            '    If m_nodelist.Item(0).ChildNodes.Item(count).Name = "SortTitle" Then
            '        indSortTitle = count
            '    End If
            'Next
            count = 0
            'Loop through the nodes
            For Each m_node In m_nodelist

                Dim inputCover As String
                Dim outputCover As String
                Dim isoFile As String
                Dim dvdFolder As String
                Dim txtTitle As String
                Dim imgThumbnail As String
                Dim txtExt As String
                Dim c As New Control
                Dim txtDirVer2 As String
                Dim txtDirVer3 As String

                For nodecount = 0 To m_node.ChildNodes.Count - 1
                    If m_node.ChildNodes.Item(nodecount).Name = "ID" Then
                        indTitleID = nodecount
                    End If
                    If m_node.ChildNodes.Item(nodecount).Name = "SortTitle" Then
                        indSortTitle = nodecount
                    End If
                Next

                Dim sortTitle = m_node.ChildNodes.Item(indSortTitle).InnerText
                Dim coverFile = m_node.ChildNodes.Item(indTitleID).InnerText

                txtTitle = CleanMovieTitle(sortTitle.ToString)

                If Me.rdoVer2.Checked Then
                    inputCover = Me.txtProfilerDir.Text & "\Images\" & coverFile.ToString & "f.jpg"
                    strVersion = "2"
                End If

                If Me.rdoVer3.Checked Then
                    inputCover = Me.txtProfilerDir.Text & "\Databases\Default\Images\" & coverFile.ToString & "f.jpg"
                    strVersion = "3"
                End If

                outputCover = Me.txtXBMCDir.Text & "\" & txtTitle & ".tbn"


                'MsgBox(inputCover & vbLf & txtTitle)
                'Exit Sub

                For Each c In Me.GroupBox1.Controls
                    If CType(c, RadioButton).Checked Then
                        txtExt = CType(c, RadioButton).Text
                    End If
                Next

                If Not Me.chkDVDFolder.Checked Then

                    'CREATE DVD Files

                    isoFile = Me.txtXBMCDir.Text & "\" & txtTitle & "." & txtExt

                    If Not File.Exists(isoFile) Then
                        SaveTextToFile("", isoFile)
                        count += 1
                    Else
                        If Me.chkDuplicates.Checked Then
                            isoFile = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 1)." & txtExt
                            outputCover = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 1).tbn"
                            If Not File.Exists(isoFile) Then
                                SaveTextToFile("", isoFile)
                                count += 1
                            Else
                                isoFile = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 2)." & txtExt
                                outputCover = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 2).tbn"
                                If Not File.Exists(isoFile) Then
                                    SaveTextToFile("", isoFile)
                                    count += 1
                                Else
                                    isoFile = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 3)." & txtExt
                                    outputCover = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 3).tbn"
                                    If Not File.Exists(isoFile) Then
                                        SaveTextToFile("", isoFile)
                                        count += 1
                                    Else
                                        isoFile = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 4)." & txtExt
                                        outputCover = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 4).tbn"
                                        If Not File.Exists(isoFile) Then
                                            SaveTextToFile("", isoFile)
                                            count += 1
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If

                    If Me.chkCreateCover.Checked Then
                        If Not File.Exists(outputCover) Then
                            If File.Exists(inputCover) Then
                                File.Copy(inputCover, outputCover)
                            End If
                        Else
                            If Me.chkOverwriteCover.Checked Then
                                If File.Exists(inputCover) Then
                                    File.Delete(outputCover)
                                    File.Copy(inputCover, outputCover)
                                End If
                            End If
                        End If
                    End If

                Else

                    'CREATE DVD FOLDERS
                    dvdFolder = Me.txtXBMCDir.Text & "\" & txtTitle
                    outputCover = Me.txtXBMCDir.Text & "\" & txtTitle & "\folder.jpg"

                    If Not Directory.Exists(dvdFolder) Then
                        Directory.CreateDirectory(dvdFolder)
                        count += 1
                    Else
                        If Me.chkDuplicates.Checked Then
                            dvdFolder = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 1)"
                            outputCover = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 1)\folder.jpg"
                            If Not Directory.Exists(dvdFolder) Then
                                Directory.CreateDirectory(dvdFolder)
                                count += 1
                            Else
                                dvdFolder = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 2)"
                                outputCover = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 2)\folder.jpg"
                                If Not Directory.Exists(dvdFolder) Then
                                    Directory.CreateDirectory(dvdFolder)
                                    count += 1
                                Else
                                    dvdFolder = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 3)"
                                    outputCover = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 3)\folder.jpg"
                                    If Not Directory.Exists(dvdFolder) Then
                                        Directory.CreateDirectory(dvdFolder)
                                        count += 1
                                    Else
                                        dvdFolder = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 4)"
                                        outputCover = Me.txtXBMCDir.Text & "\" & txtTitle & " (Duplicate 4)\folder.jpg"
                                        If Not Directory.Exists(dvdFolder) Then
                                            Directory.CreateDirectory(dvdFolder)
                                            count += 1
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If

                    If Me.chkCreateCover.Checked Then
                        If Not File.Exists(outputCover) Then
                            If File.Exists(inputCover) Then
                                File.Copy(inputCover, outputCover)
                            End If
                        Else
                            If Me.chkOverwriteCover.Checked Then
                                If File.Exists(inputCover) Then
                                    File.Delete(outputCover)
                                    File.Copy(inputCover, outputCover)
                                End If
                            End If
                        End If
                    End If

                End If

                Me.StatusBar1.Text = "Files created for " & txtTitle & "."
                Me.ProgressBar1.Increment(1)

            Next

            Me.lblLog.Text = "Finished. " & count & " new movies added."
            Me.StatusBar1.Text = "Done."

            'Save Current Configuration
            SaveConfiguration(strVersion, Me.txtProfilerDir.Text, Me.txtXML.Text, Me.txtXBMCDir.Text)

        Catch errorVariable As Exception
            'Error trapping
            MsgBox("Unexpected Error.  Please contact japhule@hotmail.com to report the bug.")
        End Try
    End Sub

    Public Function SaveTextToFile(ByVal strData As String, ByVal FullPath As String, Optional ByVal ErrInfo As String = "") As Boolean

        Dim Contents As String
        Dim bAns As Boolean = False
        Dim objReader As StreamWriter
        Try
            objReader = New StreamWriter(FullPath)
            objReader.Write(strData)
            objReader.Close()
            bAns = True
        Catch Ex As Exception
            ErrInfo = Ex.Message

        End Try
        Return bAns
    End Function

    Public Function CleanMovieTitle(ByVal strTitle As String) As String

        Dim strNewTitle As String

        strTitle = strTitle.Replace("/", " ")
        strTitle = strTitle.Replace("\", " ")
        strTitle = strTitle.Replace(":", "")
        strTitle = strTitle.Replace("<", "")
        strTitle = strTitle.Replace(">", "")
        strTitle = strTitle.Replace("*", "")
        strTitle = strTitle.Replace("?", "")
        strTitle = strTitle.Replace("""", "")
        strTitle = strTitle.Replace("|", " ")

        CleanMovieTitle = strTitle

    End Function

    Private Sub chkCreateEmptyMovie_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCreateEmptyMovie.CheckedChanged
        If Me.chkCreateEmptyMovie.Checked Then
            'select extension
            Me.GroupBox1.Enabled = True
            Me.RadioButton1.Checked = True
            Me.chkOverwriteMovie.Enabled = True
            'enable
            Me.chkDVDFolder.Enabled = True
            Me.chkDuplicates.Enabled = True
            Me.chkDVDFolder.Checked = False
            Me.chkDuplicates.Checked = False
        Else
            Me.GroupBox1.Enabled = False
            Me.chkOverwriteMovie.Enabled = False
            Me.chkOverwriteMovie.Checked = False
            'enable
            Me.chkDVDFolder.Enabled = False
            Me.chkDuplicates.Enabled = False
            Me.chkDVDFolder.Checked = False
            Me.chkDuplicates.Checked = False
        End If
    End Sub

    Private Sub chkCreateCover_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCreateCover.CheckedChanged
        If Me.chkCreateCover.Checked Then
            Me.chkOverwriteCover.Enabled = True
            Me.chkOverwriteCover.Checked = False
        Else
            Me.chkOverwriteCover.Enabled = False
            Me.chkOverwriteCover.Checked = False
        End If
    End Sub

    Public Function IsChecked(ByVal chkObj As CheckBox) As Boolean
        If chkObj.Checked = True Then
            IsChecked = True
        Else
            IsChecked = False
        End If
    End Function

    Private Sub chkDVDFolder_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkDVDFolder.CheckedChanged
        If Me.chkDVDFolder.Checked Then
            Me.GroupBox1.Enabled = False
        Else
            Me.GroupBox1.Enabled = True
        End If
    End Sub

    Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
        Dim frm2 As New Form2
        frm2.StartPosition = FormStartPosition.CenterScreen
        frm2.Show()
    End Sub

    Private Sub SaveConfiguration(ByVal version As String, ByVal dirProfiler As String, ByVal filePath As String, ByVal xbmcPath As String, Optional ByVal outputType As String = "", Optional ByVal outputExt As String = "", Optional ByVal dup As String = "", Optional ByVal overwrite As String = "", Optional ByVal createcover As String = "", Optional ByVal overwritecover As String = "")

        Dim strData As String
        Dim savedPath As String

        strData = "<Settings>" + vbCrLf

        strData += vbTab + "<Version>" + version + "</Version>" + vbCrLf

        strData += vbTab + "<ProfilerPath>" + dirProfiler + "</ProfilerPath>" + vbCrLf

        strData += vbTab + "<XMLPath>" + filePath + "</XMLPath>" + vbCrLf

        strData += vbTab + "<XBMCPath>" + xbmcPath + "</XBMCPath>" + vbCrLf

        strData += "</Settings>"

        savedPath = Windows.Forms.Application.StartupPath + "\" + "settings.ini"

        SaveTextToFile(strData, savedPath)

    End Sub

    Private Sub LoadConfiguration()

        Dim strConfigFile = Windows.Forms.Application.StartupPath + "\" + "settings.ini"
        Dim m_xmld As XmlDocument
        Dim m_nodelist As XmlNodeList
        Dim m_node As XmlNode
        Dim count As Integer

        'Create the XML Document
        m_xmld = New XmlDocument

        'Load the Xml file
        If File.Exists(strConfigFile) Then
            m_xmld.Load(strConfigFile)

        'Get the list of name nodes 
        m_nodelist = m_xmld.SelectNodes("/Settings")

        For count = 0 To m_nodelist.Item(0).ChildNodes.Count - 1
            If m_nodelist.Item(0).ChildNodes.Item(count).Name = "Version" Then
                If m_nodelist.Item(0).ChildNodes.Item(count).InnerText = "2" Then
                    Me.rdoVer2.Checked = True
                End If
                If m_nodelist.Item(0).ChildNodes.Item(count).InnerText = "3" Then
                    Me.rdoVer3.Checked = True
                End If
            End If

            If m_nodelist.Item(0).ChildNodes.Item(count).Name = "ProfilerPath" Then
                Me.txtProfilerDir.Text = m_nodelist.Item(0).ChildNodes.Item(count).InnerText
            End If

            If m_nodelist.Item(0).ChildNodes.Item(count).Name = "XMLPath" Then
                Me.txtXML.Text = m_nodelist.Item(0).ChildNodes.Item(count).InnerText
            End If

            If m_nodelist.Item(0).ChildNodes.Item(count).Name = "XBMCPath" Then
                Me.txtXBMCDir.Text = m_nodelist.Item(0).ChildNodes.Item(count).InnerText
            End If

        Next

        End If

    End Sub

    Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click
        Dim frm3 As New Form3

        If Not (Me.rdoVer2.Checked Or Me.rdoVer3.Checked) Then
            MsgBox("Please select your version of DVD Profiler")
            Exit Sub
        End If

        If Me.txtXML.Text = "" Then
            MsgBox("Please select an XML file.")
            Me.txtXML.Focus()
            Exit Sub
        End If

        If Not File.Exists(Me.txtXML.Text) Then
            MsgBox("File does not exist.  Please select a valid file.")
            Me.txtXML.Focus()
            Exit Sub
        End If

        frm3.xmlFile = Me.txtXML.Text
        frm3.dirProfile = Me.txtProfilerDir.Text

        If Me.rdoVer2.Checked Then
            frm3.strVersion = "2"
        End If

        If Me.rdoVer3.Checked Then
            frm3.strVersion = "3"
        End If

        frm3.StartPosition = FormStartPosition.CenterScreen
        frm3.Show()

    End Sub
End Class
